package cn.car91.activity;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.car91.R;
import cn.car91.bean.RepairShop;
import cn.car91.utils.ImageManager;
import cn.car91.utils.MyOrientationListener;
import cn.car91.utils.MyOrientationListener.OnOrientationListener;
import cn.car91.utils.RegexUtil;
import cn.car91.view.HerilyAlertDialog;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMap.OnMapClickListener;
import com.baidu.mapapi.map.BaiduMap.OnMapLongClickListener;
import com.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiNearbySearchOption;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;
import com.baidu.mapapi.utils.DistanceUtil;
import com.baidu.navisdk.BNaviPoint;
import com.baidu.navisdk.BaiduNaviManager;
import com.baidu.navisdk.BaiduNaviManager.OnStartNavigationListener;
import com.baidu.navisdk.comapi.routeplan.RoutePlanParams.NE_RoutePlan_Mode;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class MapActivity extends BaseActivity {
    LocationClient locationClient;
    LocationClientOption option;
    PoiSearch poiSearch;
    //public LocationClient mLocationClient = null;
    @ViewInject(R.id.bmapView)
    MapView mapView;
    @ViewInject(R.id.header_other)
    TextView headerOther;
    private BaiduMap mBaiduMap = null;
    private InfoWindow mInfoWindow;
    //public BDLocationListener myListener = new MyLocationListener();

    String tip = "你的位置";
    String tip_tmp = "地图选点";
    boolean onlyNav = false;
    BitmapDescriptor bitmap;
    OverlayOptions centeroption;
    MyOrientationListener myOrientationListener;
    Double lon;
    Double lat;
    BNaviPoint startPoint;
    BNaviPoint endPoint;
    LatLng point;
    String key=null;

    int mXDirection;
    float mCurrentAccracy;
    float mCurrentLantitude;
    float mCurrentLongitude;

    int mapType = 0;

    public interface MapType {
        /**
         * 附近商家
         */
        final int MAP_TYPE_AOUND_REPAIRSHOP = 0;
        /**
         * 周边路况
         */
        final int MAP_TYPE_AOUND_TRAFFIC = 1;
        /**
         * 周边加油站
         */
        final int MAP_TYPE_AOUND_OIL = 2;
        /**
         * 周边服务设施
         */
        final int MAP_TYPE_AOUND_ALL = 3;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext  
        //注意该方法要再setContentView方法之前实现  
        setContentView(R.layout.activity_map);
        super.onCreate(savedInstanceState);

        //设置定位条件
        option = getCar91Application().getLocationOption();
        option.setScanSpan(getCar91Application().UPDATE_TIME_SHORT);    //设置定时定位的时间间隔。单位毫秒

        locationClient = getCar91Application().getmLocationClient();
        locationClient.setLocOption(option);

        mapView.removeViewAt(1); // 去掉百度logo
        mBaiduMap = mapView.getMap();
        mBaiduMap.setOnMapClickListener(new OnMapClickListener() {
			@Override
			public boolean onMapPoiClick(MapPoi arg0) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void onMapClick(LatLng arg0) {
				mBaiduMap.hideInfoWindow();
			}
		});

        mapType = getIntent().getIntExtra("mapType", MapType.MAP_TYPE_AOUND_REPAIRSHOP);
        Integer zoom = getIntent().getIntExtra("zoom", 15);
        lon = getIntent().getDoubleExtra("lon", 116.40);
        lat = getIntent().getDoubleExtra("lat", 39.91);

        //定义Maker坐标点  
        point = new LatLng(lat, lon);
        startPoint = new BNaviPoint(lon, lat, tip, BNaviPoint.CoordinateType.BD09_MC);
        //定义地图状态
        MapStatus mMapStatus = new MapStatus.Builder().target(point).zoom(zoom).build();
        //定义MapStatusUpdate对象，以便描述地图状态将要发生的变化
        MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
        //改变地图状态
        mBaiduMap.setMapStatus(mMapStatusUpdate);
        
        switch (mapType) {
            case MapType.MAP_TYPE_AOUND_REPAIRSHOP:
                RepairShop shop = (RepairShop) getIntent().getSerializableExtra("repairshop");
                if (shop == null) {
                    ((TextView) findViewById(R.id.header_text)).setText(R.string.around_map_item);
                } else {
                    onlyNav = true;
                    tip = shop.getName();
                    ((TextView) findViewById(R.id.header_text)).setText(shop.getName());
                }

                //构建Marker图标
                if (!onlyNav) {
                    bitmap = BitmapDescriptorFactory.fromResource(R.drawable.map_point_blue);
                    centeroption = new MarkerOptions()
                            .title(tip)
                            .position(point)
                            .icon(bitmap);
                    mBaiduMap.addOverlay(centeroption);
                } else {
                    locationClient.registerLocationListener(bdLocationLinstener);
                    bitmap = BitmapDescriptorFactory.fromResource(R.drawable.map_point_red);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("repairshop", shop);
                    centeroption = new MarkerOptions()
                            .title(tip)
                            .extraInfo(bundle)
                            .position(point)
                            .icon(bitmap);
                    mBaiduMap.addOverlay(centeroption);
                    //initShowPopu(point.longitude,point.latitude,shop);
                }

                List<RepairShop> repairShops = (List<RepairShop>) getIntent().getSerializableExtra("points");
                if (repairShops != null) {
                    for (RepairShop repairShop : repairShops) {
                        String position = repairShop.getDetail().getPosition();
                        if (RegexUtil.isNotNull(position)) {
                            try {
                                String[] tmp = position.split(",");
                                point = new LatLng(Double.parseDouble(tmp[1]), Double.parseDouble(tmp[0]));
                                bitmap = BitmapDescriptorFactory.fromResource(R.drawable.map_point_red);
                                Bundle bundle = new Bundle();
                                bundle.putSerializable("repairshop", repairShop);
                                centeroption = new MarkerOptions()
                                        .title(repairShop.getName())
                                        .position(point)
                                        .extraInfo(bundle)
                                        .icon(bitmap);
                                mBaiduMap.addOverlay(centeroption);
                            } catch (Exception e) {
                                Toast.makeText(MapActivity.this, repairShop.getName() + "--坐标异常", Toast.LENGTH_SHORT).show();
                                continue;
                            }
                        }
                    }
                }
                break;
            case MapType.MAP_TYPE_AOUND_TRAFFIC:
                myOrientationListener = new MyOrientationListener(getApplicationContext());
                myOrientationListener.setOnOrientationListener(new OnOrientationListener() {
                    @Override
                    public void onOrientationChanged(float x) {
                        initCurrent(locationClient.getLastKnownLocation().getLongitude(), locationClient.getLastKnownLocation().getLatitude(), x);
                    }
                });
                headerOther.setText("我的位置");
                ((View)headerOther.getParent()).setVisibility(View.VISIBLE);
                myOrientationListener.start();
                //mBaiduMap.setonmapt
                mBaiduMap.setMyLocationEnabled(true);
                mBaiduMap.setTrafficEnabled(true);
                option.setScanSpan(getCar91Application().UPDATE_TIME_MUST_SHORT);
                locationClient.setLocOption(option);
                locationClient.registerLocationListener(locationListener);
                locationClient.start();
                if (locationClient.isStarted())
                    locationClient.requestOfflineLocation();
                ((TextView) findViewById(R.id.header_text)).setText("实时路况");
                break;
            case MapType.MAP_TYPE_AOUND_ALL:
                bitmap = BitmapDescriptorFactory.fromResource(R.drawable.map_point_blue);
                centeroption = new MarkerOptions()
                        .title(tip)
                        .position(point)
                        .icon(bitmap);
                mBaiduMap.addOverlay(centeroption);
                key = getIntent().getStringExtra("nearkey");
                mBaiduMap.setOnMapLongClickListener(new OnMapLongClickListener() {
					@Override
					public void onMapLongClick(LatLng arg0) {
						mBaiduMap.clear();
						centeroption = new MarkerOptions()
	                        .title(tip_tmp)
	                        .position(arg0)
	                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_point_blue));
						mBaiduMap.addOverlay(centeroption);
						headerOther.setText("我的附近");
		                ((View)headerOther.getParent()).setVisibility(View.VISIBLE);
						searchAround(key,arg0);
					}
				});
                ((TextView) findViewById(R.id.header_text)).setText("附近—" + key);
                searchAround(key,point);
                break;
            default:
                break;
        }

        mBaiduMap.setOnMarkerClickListener(onMarkerClickListener);
    }

    private OnMarkerClickListener onMarkerClickListener = new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker arg0) {
            // TODO Auto-generated method stub
            showLocation(arg0);
            return false;
        }
    };

    private void showLocation(final Marker marker) {  //显示气泡
        // 创建InfoWindow展示的view
        mBaiduMap.hideInfoWindow();//影藏气泡
        if (RegexUtil.isNotNull(marker.getTitle())) {
            if (onlyNav) {
                turnPopu(marker);
            } else if (!(marker.getTitle().equals(tip)||marker.getTitle().equals(tip_tmp))) {
                turnPopu(marker);
            }
            //定义地图状态
            MapStatus mMapStatus = new MapStatus.Builder()
                    .target(marker.getPosition())
                    .zoom(mBaiduMap.getMapStatus().zoom)
                    .build();
            //改变地图状态
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mMapStatus));
        }
    }
    
    /*private void initShowPopu(final double latitude,final double longitude,final RepairShop repairShop){
    	LatLng pt = null;
        View view = null, hidPopu = null, nav = null;
        view = LayoutInflater.from(this).inflate(R.layout.view_map_pop_info, null); //自定义气泡形状
        TextView nameText = (TextView) view.findViewById(R.id.map_repairshop_name);
        TextView idText = (TextView) view.findViewById(R.id.map_repairshop_id);
        TextView addressText = (TextView) view.findViewById(R.id.map_repairshop_address);
        TextView phoneText = (TextView) view.findViewById(R.id.map_repairshop_phone);
        ImageView imageView = (ImageView) view.findViewById(R.id.map_repairshop_pic);
        View detailView = view.findViewById(R.id.map_repairshop_detail);
        hidPopu = view.findViewById(R.id.map_repairshop_close);
        //TextView infoText = (TextView) view.findViewById(R.id.map_repairshop_info);
        nav = view.findViewById(R.id.map_repairshop_to);

        nameText.setText(repairShop.getName());
        idText.setText(repairShop.getId());
        addressText.setText(repairShop.getDetail().getAddress());
        phoneText.setText(repairShop.getDetail().getPhone());

        ImageManager imageManager = new ImageManager(MapActivity.this, "sdcard/car91/temp/repairshop");
        String picImg = getCar91Application().getCenterServerUrl() + "/" + repairShop.getLogo();
        try {
            int index = repairShop.getLogo().lastIndexOf("/");
            picImg = getCar91Application().getCenterServerUrl() + "/" + repairShop.getLogo().substring(0, index) + "/imgco" + repairShop.getLogo().substring(index, repairShop.getLogo().length());
        } catch (Exception e) {}
        
        imageManager.displayImage(picImg, imageView, getResources().getDrawable(R.drawable.ico_launcher));

        detailView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                if (onlyNav) {
                    finish();
                } else {
                    Intent intent = new Intent();
                    intent.putExtra("rid", repairShop.getId());
                    intent.setClass(MapActivity.this, RepairShopDetailActivity.class);
                    startActivity(intent);
                }
            }
        });
        pt = new LatLng(latitude, longitude);
        mInfoWindow = new InfoWindow(view, pt, -60);
        mBaiduMap.showInfoWindow(mInfoWindow); //显示气泡
        
        hidPopu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                mBaiduMap.hideInfoWindow();//影藏气泡
            }
        });
        nav.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
            	toNavi(longitude,latitude,repairShop.getName());
            }
        });
    }*/

    private void turnPopu(final Marker marker) {
        LatLng pt = null;
        double latitude, longitude;
        latitude = marker.getPosition().latitude;
        longitude = marker.getPosition().longitude;
        View view = null, hidPopu = null, nav = null;
        switch (mapType) {
            case MapType.MAP_TYPE_AOUND_REPAIRSHOP:
                view = LayoutInflater.from(this).inflate(R.layout.view_map_pop_info, null); //自定义气泡形状
                TextView nameText = (TextView) view.findViewById(R.id.map_repairshop_name);
                TextView idText = (TextView) view.findViewById(R.id.map_repairshop_id);
                TextView addressText = (TextView) view.findViewById(R.id.map_repairshop_address);
                TextView phoneText = (TextView) view.findViewById(R.id.map_repairshop_phone);
                ImageView imageView = (ImageView) view.findViewById(R.id.map_repairshop_pic);
                View detailView = view.findViewById(R.id.map_repairshop_detail);
                hidPopu = view.findViewById(R.id.map_repairshop_close);
                //TextView infoText = (TextView) view.findViewById(R.id.map_repairshop_info);
                nav = view.findViewById(R.id.map_repairshop_to);

                Bundle bundle = marker.getExtraInfo();
                final RepairShop repairShop = (RepairShop) bundle.getSerializable("repairshop");
                nameText.setText(repairShop.getName());
                idText.setText(repairShop.getId());
                addressText.setText(repairShop.getDetail().getAddress());
                phoneText.setText(repairShop.getDetail().getPhone());

                ImageManager imageManager = new ImageManager(MapActivity.this, "sdcard/car91/temp/repairshop");
                String picImg = getCar91Application().getCenterServerUrl() + "/" + repairShop.getLogo();
                try {
                    int index = repairShop.getLogo().lastIndexOf("/");
                    picImg = getCar91Application().getCenterServerUrl() + "/" + repairShop.getLogo().substring(0, index) + "/imgco" + repairShop.getLogo().substring(index, repairShop.getLogo().length());
                } catch (Exception e) {}
                
                imageManager.displayImage(picImg, imageView, getResources().getDrawable(R.drawable.ico_launcher));

                detailView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        if (onlyNav) {
                            finish();
                        } else {
                            Intent intent = new Intent();
                            intent.putExtra("rid", repairShop.getId());
                            intent.setClass(MapActivity.this, RepairShopDetailActivity.class);
                            startActivity(intent);
                        }
                    }
                });
                break;
            case MapType.MAP_TYPE_AOUND_ALL:
                view = LayoutInflater.from(this).inflate(R.layout.view_map_pop_round_info, null); //自定义气泡形状
                TextView name = (TextView) view.findViewById(R.id.map_round_title);
                TextView address = (TextView) view.findViewById(R.id.map_round_address);
                TextView dis = (TextView) view.findViewById(R.id.map_round_distance);
                hidPopu = view.findViewById(R.id.map_round_close);
                //TextView infoText = (TextView) view.findViewById(R.id.map_repairshop_info);
                nav = view.findViewById(R.id.map_round_to);
                
                Bundle bundle1 = marker.getExtraInfo();
                String nam = bundle1.getString("poiname");
                String addr = bundle1.getString("poiaddr");
                double distance = bundle1.getDouble("poidistance", 0);
                name.setText(nam);
                address.setText(addr);
                if(distance > 5000){
                    dis.setText(String.format("%.1f", distance/1000)+"km");
                  }else{
                    int di = (int)distance;
                    dis.setText(di+"m");
                  }
                break;
            default:
                break;
        }
        pt = new LatLng(latitude, longitude);
        mInfoWindow = new InfoWindow(view, pt, -60);
        mBaiduMap.showInfoWindow(mInfoWindow); //显示气泡
        
        hidPopu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                mBaiduMap.hideInfoWindow();//影藏气泡
            }
        });
        nav.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                toNavi(marker.getPosition().longitude,marker.getPosition().latitude,marker.getTitle());
            }
        });
    }

    private void toNavi(double lon,double lat,String title) {

        if (onlyNav) {
            if (startPoint == null) {
                new HerilyAlertDialog.Builder(MapActivity.this).setMessage("正在定位中...").create().show();
                return;
            }
        }
        /*endPoint = new BNaviPoint(marker.getPosition().longitude,marker.getPosition().latitude,
			marker.getTitle(), BNaviPoint.CoordinateType.BD09_MC);  */
        endPoint = new BNaviPoint(lon, lat, title, BNaviPoint.CoordinateType.BD09_MC);
        BaiduNaviManager.getInstance().launchNavigator(this,
                startPoint, endPoint,
                NE_RoutePlan_Mode.ROUTE_PLAN_MOD_MIN_TIME,       //算路方式  
                true,                                            //真实导航  
                BaiduNaviManager.STRATEGY_FORCE_ONLINE_PRIORITY, //在离线策略  
                new OnStartNavigationListener() {                //跳转监听  
                    @Override
                    public void onJumpToNavigator(Bundle configParams) {
                        Intent intent = new Intent(MapActivity.this, MapNavigatorActivity.class);
                        intent.putExtras(configParams);
                        startActivity(intent);
                    }

                    @Override
                    public void onJumpToDownloader() {
                    }
                });
    }

    private void searchAround(String key,LatLng point){
    	poiSearch = PoiSearch.newInstance();
        poiSearch.setOnGetPoiSearchResultListener(poiListener);
        PoiNearbySearchOption nearOption = new PoiNearbySearchOption();
        
        nearOption.keyword(key);
        nearOption.location(point);
        nearOption.radius(5 * 1000);
        nearOption.pageCapacity(50);
        poiSearch.searchNearby(nearOption);
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (locationClient.isStarted())
            locationClient.stop();
        option.setScanSpan(getCar91Application().UPDATE_TIME_SUPER_LONG);
        locationClient.setLocOption(option);
        if (myOrientationListener != null)
            myOrientationListener.stop();
        try {
            locationClient.unRegisterLocationListener(locationListener);
        } catch (Exception e) {
        }
        if (poiSearch != null)
            poiSearch.destroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        if (mapView != null)
            mapView.onDestroy();
    }

    @Override
    protected void onResume() {
        if (onlyNav) {
            option.setScanSpan(getCar91Application().UPDATE_TIME_SHORT);
            locationClient.setLocOption(option);

            if (!locationClient.isStarted())
                locationClient.start();

            if (locationClient.isStarted())
                locationClient.requestOfflineLocation();
        }

        super.onResume();
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        if (mapView != null)
            mapView.onResume();
    }

    OnGetPoiSearchResultListener poiListener = new OnGetPoiSearchResultListener() {
        public void onGetPoiResult(PoiResult result) {
            //获取POI检索结果
            bitmap = BitmapDescriptorFactory
                    .fromResource(R.drawable.map_point_red);
            List<PoiInfo> pois = result.getAllPoi();
            try {
                for (PoiInfo poiInfo : pois) {
                    Bundle bundle = new Bundle();
                    bundle.putString("poiname", poiInfo.name);
                    bundle.putString("poiaddr", poiInfo.address);
                    bundle.putDouble("poidistance", DistanceUtil.getDistance(point, poiInfo.location));
                    centeroption = new MarkerOptions()
                            .title(poiInfo.name)
                            .position(poiInfo.location)
                            .extraInfo(bundle)
                            .icon(bitmap);
                    mBaiduMap.addOverlay(centeroption);
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
        }

        public void onGetPoiDetailResult(PoiDetailResult result) {
            //获取Place详情页检索结果
        }
    };

    BDLocationListener locationListener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(BDLocation arg0) {
            // TODO Auto-generated method stub
            if (arg0 == null)
                arg0 = locationClient.getLastKnownLocation();
            // 开启定位图层
            //mBaiduMap.setMyLocationEnabled(true);
            
            // 构造定位数据
            float direction = 0;
            try {
                direction = myOrientationListener.getLastX();
            } catch (Exception e) {
            }
            initCurrent(arg0.getLongitude(), arg0.getLatitude(), direction);
        }
    };

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        if (mapView != null)
            mapView.onPause();
    }

    private void initCurrent(double lon, double lat, float direction) {
        MyLocationData locData = new MyLocationData.Builder()
                .accuracy(locationClient.getLastKnownLocation().getRadius())
                        // 此处设置开发者获取到的方向信息，顺时针0-360
                .direction(direction)
                .latitude(lat)
                .longitude(lon)
                .build();
        // 设置定位数据
        mBaiduMap.setMyLocationData(locData);
        // 设置定位图层的配置（定位模式，是否允许方向信息，用户自定义定位图标）
        BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory
                .fromResource(R.drawable.direction_blue);
        MyLocationConfiguration config = new MyLocationConfiguration(LocationMode.NORMAL, true, mCurrentMarker);
        //mBaiduMap.setMyLocationConfiguration();
        mBaiduMap.setMyLocationConfigeration(config);
        /*LatLng ll = new LatLng(lat, lon);
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        mBaiduMap.animateMapStatus(u);*/
    }

    private BDLocationListener bdLocationLinstener = new BDLocationListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // TODO Auto-generated method stub
            if (location == null)
                location = locationClient.getLastKnownLocation();
            try {
                startPoint = new BNaviPoint(location.getLongitude(), location.getLatitude(),
                        "当前位置", BNaviPoint.CoordinateType.BD09_MC);
            } catch (Exception e) {
                startPoint = null;
            }
        }
    };
    
    @OnClick(R.id.header_other)
    public void toCenterClcik(View view){
    	try {
    		double llat = locationClient.getLastKnownLocation().getLatitude();
        	double llon = locationClient.getLastKnownLocation().getLongitude();
    		
            MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(new LatLng(llat, llon));
            mBaiduMap.animateMapStatus(u);
            
            switch (mapType) {
			case MapType.MAP_TYPE_AOUND_ALL:
				if(RegexUtil.isNotNull(key))
					searchAround(key, new LatLng(llat, llon));
					((View)headerOther.getParent()).setVisibility(View.GONE);
					mBaiduMap.clear();
					centeroption = new MarkerOptions()
		                .title(tip)
		                .position(new LatLng(llat, llon))
		                .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_point_blue));
					mBaiduMap.addOverlay(centeroption);
				break;

			default:
				break;
			}
		} catch (Exception e) {}
    }
}
